﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SQLExecute;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.Security;



public partial class profile_edu : System.Web.UI.Page
{
    MajorSubject m = new MajorSubject();
    school s = new school();
    DataSet ds;
    Common c = new Common();
    Recruitment_Information r = new Recruitment_Information();
    Skills_And_Qualifications skills = new Skills_And_Qualifications();
    Working_Experience workingExperience = new Working_Experience();
    Interview_Evaluation interview = new Interview_Evaluation();


    public static int form_id;
    public static string form_name;

    public string strConnect = Common.strConnect;
    
    public string strMessage=string.Empty;

    private static string strImageProfile = string.Empty;

    public profile_edu()
    {
        form_id = 1;
        form_name = "New profile";

    }

    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            if (Session["username"] != null)
            {
                AddOnClick();
                InitCombo();
                radioUSD.Checked = true;
                beforeSalaryUSD.Checked = true;
                txtInterView1.Text = "Mrs. Lệ Mỹ";
                txtInterViewPos1.Text = "HR Excutive";
                txtFinalDecision.Text = "Mrs Thiên An";
                txtInterViewPos3.Text = "HR Director";
                lUsername.Text = Session["username"].ToString();
              
                

            }
            else Response.Redirect("../login/login.aspx");
        }


    }

    private void Get_Known_Us()
    { 
        Common c=new Common();
        cbKnownUs.DataSource = c.Get_Known_Us();
        cbKnownUs.DataTextField = "known_from";
        cbKnownUs.DataValueField= "id";
        cbKnownUs.DataBind();
        cbKnownUs.SelectedIndex = 0;
    }

    private void AddOnClick()
    {
        beforeSalaryUSD.Attributes.Add("OnClick", "beforeSalaryUSDCheck();");
        beforeSalaryVND.Attributes.Add("OnClick", "beforeSalaryVNDCheck();");

        radioUSD.Attributes.Add("OnClick","checkSalaryUSD();");
        radioVND.Attributes.Add("OnClick", "checkSalaryVND();");
        chkMale.Attributes.Add("OnClick", "checkMale();");
        chkFemale.Attributes.Add("OnClick", "checkFemale();");

        chkSingle.Attributes.Add("OnClick", "checkSingle();");
        chkMarried.Attributes.Add("OnClick", "checkMarried();");
      
        chkRelocateYes.Attributes.Add("OnClick", "checkRelocateYes();");
        chkRelocateNo.Attributes.Add("OnClick", "checkRelocateNo();");
        chkRelocateNotSure.Attributes.Add("OnClick", "checkRelocateNotSure();");

        chkMaster.Attributes.Add("OnClick", "checkMaster();");
        chkBachelor.Attributes.Add("OnClick", "checkBachelor();");
        chkDiploma.Attributes.Add("OnClick", "checkDiploma();");
        chkAssociate.Attributes.Add("OnClick", "checkAssociate();");
        chkOtherDeg.Attributes.Add("OnClick", "checkOtherDeg();");

        chkBasic.Attributes.Add("OnClick", "checkBasic();");
        chkIntermediate.Attributes.Add("OnClick", "checkIntermediate();");
        chkAdvance.Attributes.Add("OnClick", "checkAdvance();");

        chkComputerSkillBasic.Attributes.Add("OnClick", "checkComputerSkillBasic();");
        chkComputerSkillIntermediate.Attributes.Add("OnClick", "checkComputerSkillIntermediate();");
        chkComputerSkillAdvance.Attributes.Add("OnClick", "checkComputerSkillAdvance();");

        chkRejected.Attributes.Add("OnClick", "checkRejected();");
        chkKIV.Attributes.Add("OnClick", "checkKIV();");
        chkAccepted.Attributes.Add("OnClick", "checkAccepted();");

        chkRejected1.Attributes.Add("OnClick", "checkRejected1();");
        chkKIV1.Attributes.Add("OnClick", "checkKIV1();");
        chkAccepted1.Attributes.Add("OnClick", "checkAccepted1();");


        chkFinalAccept.Attributes.Add("OnClick", "checkFinalAccept();");
        chkFinalRejected.Attributes.Add("OnClick", "checkFinalRejected();");
        chkFinalConsiderMore.Attributes.Add("OnClick", "checkFinalConsiderMore();");
    }
    private void InitCombo()
    {
       
        ds = c.Select_Common();
        c.Init_KnownUs(this.cbKnownUs);      
        c.Init_Graduation_Degree(this.cbGraduationDegree1, this.cbGraduationDegree2, this.cbGraduationDegree3, this.cbGraduationDegree4);
        m.Init_Major_Subject2(cbMajor1, cbMajor2, cbMajor3,cbMajor4);
        s.Init_Schools(cbSchool1, cbSchool2, cbSchool3, cbSchool4);
        
        c.InitTypeOfTraining(this.cbTypeOfTraining1, this.cbTypeOfTraining2, this.cbTypeOfTraining3, this.cbTypeOfTraining4);        
        r.Init_Company(cbCompany);
       
    }
   
    private static void ResetControl(Page mypage)
    { 
        
        Control myForm = mypage.FindControl("Form1");
        foreach (Control ctrl in myForm.Controls)
        {
            //Clears TextBox
            if (ctrl is System.Web.UI.WebControls.TextBox)
            {
                (ctrl as TextBox).Text = string.Empty;
            }
            if (ctrl is System.Web.UI.WebControls.RadioButton)
            {
                (ctrl as RadioButton).Checked=false;
            }
            if (ctrl is System.Web.UI.WebControls.CheckBox)
            {
                (ctrl as CheckBox).Checked=false;
            }
            if (ctrl is System.Web.UI.WebControls.DropDownList)
            { 
             (ctrl as DropDownList).SelectedIndex=0;
            }
        }
        
            

    }
    
    private void Set_Recruitment_Info()
    {
        if (chkFinalAccept.Checked)
            r.ConclusionRecruitmentInformation = chkFinalAccept.Text;
        if (chkFinalConsiderMore.Checked)
            r.ConclusionRecruitmentInformation = chkFinalConsiderMore.Text;
        if (chkFinalRejected.Checked)
            r.ConclusionRecruitmentInformation = chkFinalRejected.Text;

        r.PositionOffer = txtPositionOffer.Text;
        r.RecruitmentDep = txtRecruitmentDept.Text;
        if (txtRecruitmentSalary.Text != "")
        {  
            r.RecruitmentSalary = Convert.ToInt32(txtRecruitmentSalary.Text);
        }
        if (txtRecruitmentStartingDate.Text != "")
        {
            string s = Common.Convert_DDMMYYYY_To_MMDDYYY(txtRecruitmentStartingDate.Text);
            r.RecruitmentStartingDateTime = DateTime.Parse(s);
        }
        else r.RecruitmentStartingDateTime = DateTime.Parse("01/01/1900");
        r.RecruitemtNote = txtNote.Text;
        if (cbCompany.SelectedValue != "CHOOSE ONE")
            r.Company = cbCompany.SelectedValue;
        
        r.SendMail = 0;//chua gui mail rejected

    }
    private void Set_Interview_Evaluation()
    {
        interview.InterView1 = txtInterView1.Text;
        interview.InterViewPos1 = txtInterViewPos1.Text;
        interview.InterViewDep1 = txtInterViewDept1.Text;
        interview.Comment1 = txtComment1.Text;

        interview.EnglishResult = txtEnglish.Text;
        interview.SkillWord = txtWord.Text;
        interview.SkillExcel = txtExcel.Text;
        
        
        if (chkAccepted.Checked)
            interview.Conclusion = chkAccepted.Text;
        if (chkKIV.Checked)
            interview.Conclusion = chkKIV.Text;
        if (chkRejected.Checked)
            interview.Conclusion = chkRejected.Text;


        if (chkAccepted1.Checked)
            interview.Conclusion1 = chkAccepted1.Text;
        if (chkKIV1.Checked)
            interview.Conclusion1 = chkKIV1.Text;
        if (chkRejected1.Checked)
            interview.Conclusion1 = chkRejected1.Text;

        interview.InterView2 = txtInterView2.Text;
        interview.InterViewPos2 = txtInterViewPos2.Text;
        interview.InterViewDep2 = txtInterViewDept2.Text;
        interview.Comment2 = txtComment2.Text;

        interview.FinalDecision = txtFinalDecision.Text;
        interview.InterViewPos3 = txtInterViewPos3.Text;
        interview.InterViewDep3 = txtInterViewDept3.Text;
        interview.Comment3 = txtComment3.Text;


    
    }
    private void Set_Skills_And_Qualifications()
    {
        if (cbMajor1.SelectedIndex > 0)
            skills.Major1 =Convert.ToInt16(cbMajor1.SelectedValue);

        if (cbMajor2.SelectedIndex > 0)        
            skills.Major2 =Convert.ToInt16(cbMajor2.SelectedValue);
        if (cbMajor3.SelectedIndex > 0)        
            skills.Major3 =Convert.ToInt16(cbMajor3.SelectedValue);
        if (cbMajor4.SelectedIndex > 0)        
            skills.Major4 =Convert.ToInt16(cbMajor4.SelectedValue);

        if (cbSchool1.SelectedIndex>0)
            skills.School1 = cbSchool1.SelectedValue;

        if (cbSchool2.SelectedIndex > 0)
            skills.School2 = cbSchool2.SelectedValue;
        if (cbSchool3.SelectedIndex > 0)
            skills.School3 = cbSchool3.SelectedValue;
        if (cbSchool3.SelectedIndex>0)
            skills.School4 = cbSchool4.SelectedValue;
       
        if (cbTypeOfTraining1.SelectedIndex>0)
            skills.Typetraining1 = cbTypeOfTraining1.SelectedValue;
        if (cbTypeOfTraining2.SelectedIndex > 0)
            skills.Typetraining2 = cbTypeOfTraining2.SelectedValue;
        if (cbTypeOfTraining3.SelectedIndex > 0)
            skills.Typetraining3 = cbTypeOfTraining3.SelectedValue;
        if (cbTypeOfTraining4.SelectedIndex > 0)
            skills.Typetraining4 = cbTypeOfTraining4.SelectedValue;
        
        if (cbGraduationDegree1.SelectedIndex>0)
            skills.InfoDegree1 = cbGraduationDegree1.SelectedValue;
        if (cbGraduationDegree2.SelectedIndex > 0)
            skills.InfoDegree2 = cbGraduationDegree2.SelectedValue;
        if (cbGraduationDegree3.SelectedIndex > 0)
            skills.InfoDegree3 = cbGraduationDegree3.SelectedValue;
        if (cbGraduationDegree4.SelectedIndex > 0)
            skills.InfoDegree4 = cbGraduationDegree4.SelectedValue;

        skills.Info_Degree_Date1 = txtStudyPeriod1.Text;
        skills.Info_Degree_Date2 = txtStudyPeriod2.Text;
        skills.Info_Degree_Date3 = txtStudyPeriod3.Text;//cbStudyPeriod5.Text + "-" + cbStudyPeriod6.Text;
        skills.Info_Degree_Date4 = txtStudyPeriod4.Text;//cbStudyPeriod7.Text + "-" + cbStudyPeriod8.Text;

        if (chkBasic.Checked)
            skills.EnglishSkills = chkBasic.Text;
        if (chkIntermediate.Checked)
            skills.EnglishSkills = chkIntermediate.Text;
        if (chkAdvance.Checked)
            skills.EnglishSkills = chkAdvance.Text;
                
        if (chkComputerSkillBasic.Checked)
            skills.ComputerSkills = chkComputerSkillBasic.Text;
        if (chkComputerSkillIntermediate.Checked)
            skills.ComputerSkills = chkComputerSkillIntermediate.Text;
        if (chkComputerSkillAdvance.Checked)
            skills.ComputerSkills = chkComputerSkillAdvance.Text;

        skills.OtherLanguage = txtOtherLanguage.Text;
        skills.OtherSkills = txtOtherSkills.Text;

        if (chkMaster.Checked)
            skills.DegreeType = "Master";
        if (chkBachelor.Checked)
            skills.DegreeType = "Bachelor";
        if (chkDiploma.Checked)
            skills.DegreeType = "Diploma";
        if (chkAssociate.Checked)
            skills.DegreeType = "Associate";
        if (chkOtherDeg.Checked)
            skills.DegreeType = "Other degree";
       

    }
    private void Set_Working_Experience()
    {
        
        workingExperience.Employer1=txtEmployer1.Text;
        workingExperience.Employer2=txtEmployer2.Text;
        workingExperience.Employer3=txtEmployer3.Text;

        workingExperience.Pos1 = txtPosition1.Text;
        workingExperience.Pos2 = txtPosition2.Text;
        workingExperience.Pos3 = txtPosition3.Text;
       
        txtSalary1.Text = txtSalary1.Text.Trim();
        txtSalary1.Text = txtSalary1.Text.Replace(",", "");
        txtSalary2.Text = txtSalary2.Text.Trim();
        txtSalary2.Text = txtSalary2.Text.Replace(",", "");
        txtSalary3.Text = txtSalary3.Text.Trim();
        txtSalary3.Text = txtSalary3.Text.Replace(",", "");


        if (txtSalary1.Text!="")
            workingExperience.Salary1 =Convert.ToInt32(txtSalary1.Text);


        if (txtSalary2.Text!="")
            workingExperience.Salary2 = Convert.ToInt32(txtSalary2.Text);
        if (txtSalary3.Text!="")
            workingExperience.Salary3 = Convert.ToInt32(txtSalary3.Text);
   

        if (beforeSalaryUSD.Checked)
            workingExperience.TypeSalary = beforeSalaryUSD.Text;
        if (beforeSalaryVND.Checked)
            workingExperience.TypeSalary = beforeSalaryVND.Text;

        workingExperience.Supervisor1 = txtSupervisor1.Text;       
        workingExperience.Supervisor2 = txtSupervisor2.Text;
        workingExperience.Supervisor3 = txtSupervisor3.Text;

      

    
    }

    private void Set_Self_Evaluation(Profiles p)
    {
     
        p.CarreerObjectives = txtCarreerObjectives.Text;


    }

    private void Set_Personal_Info(Profiles p)
    {
       
        
        p.Fullname = txtFullName.Text;
        if (txtBirth.Text != "")
        {

            string s = Convert_DDMMYYYY_To_MMDDYYY(txtBirth.Text);         
            p.Birth = DateTime.Parse(s);
        }
        else p.Birth = DateTime.Parse("01/01/1900");

         

        if (chkMale.Checked)
            p.Sex = "Male";
        else if (chkFemale.Checked) p.Sex = "Female";
        if (txtHeight.Text != "")
            p.Height = Convert.ToInt16(txtHeight.Text);
        else p.Height = 0;
        if (txtWeight.Text != "")
            p.Weight = Convert.ToInt16(txtWeight.Text);
        else p.Weight = 0;


        if (chkMarried.Checked)
            p.Married = "Married";
        if (chkSingle.Checked)
            p.Married = "Single";
     
        p.OthersMartialStatus = txtOtherMartialStatus.Text;
     
        if (txtNumberChildren.Text != "")
            p.NumberOfChildrens = txtNumberChildren.Text;


        p.Phone = txtPhone.Text;
        p.Mail = txtMail.Text;
        p.IDCard = txtIDCard.Text;
        if (txtDateIDCard.Text != "")
        {
            string s =Common.Convert_DDMMYYYY_To_MMDDYYY(txtDateIDCard.Text);
            p.DateIssueIDCard = DateTime.Parse(s);
        }
        else p.DateIssueIDCard=DateTime.Parse("01/01/1900");


        p.PlaceIssueIDCard = txtPlaceIssueIDCard.Text;

        p.PermanentAddress = txtPermanentAddress.Text;
      
        p.CurrentAddress = txtCurrentAddress.Text;
     
        if (chkRelocateNo.Checked)
            p.Relocate = chkRelocateNo.Text;
        if (chkRelocateYes.Checked)
            p.Relocate = chkRelocateYes.Text;
        if (chkRelocateNotSure.Checked)
            p.Relocate = chkRelocateNotSure.Text;
        
        p.Aptitude = txtAptitude.Text;
        p.ImageURL = strImageProfile;
       
    }
    private string Convert_DDMMYYYY_To_MMDDYYY(string s)
    {

        string month, day, year;

        int n1 = s.IndexOf("/", 0);

        day = s.Substring(0, n1);

        int n2 = s.IndexOf("/", n1 + 1);
        month = s.Substring(n1 + 1, n2 - (n1 + 1));

        year = s.Substring(s.Length - 4, 4);

        //n = s.IndexOf("/", n);
        //month=s.Substring(n+1,

        s = month + "/" + day + "/" + year;
        return s;
    }
    private void Set_Basic_Info(Profiles p)
    {
        DateTime dateResult;
        CultureInfo culture;
        DateTimeStyles styles=DateTimeStyles.None;

        Guid id = new Guid();
        id = Guid.NewGuid();
        p.ID = id;
        p.ProfileType = "Educapital";//chinh sua cho nay
        p.PositionApply = txtPosition.Text;

        culture=CultureInfo.CreateSpecificCulture("fr-FR");
        if (DateTime.TryParse(txtAvailableDate.Text, culture, styles, out dateResult))

            p.AvailableDate = DateTime.Parse(dateResult.ToShortDateString());

        else

            p.AvailableDate = DateTime.Parse("01/01/1900");
            
            //msgBox.ShowMessage("Avaible date is not correct format (dd/mm/yyyy)");
            


        if (txtExpectedSalary.Text != "")
        {
            string s;
            s = txtExpectedSalary.Text.Trim();
            s=s.Replace(",","");
            p.ExpectedSalary = Convert.ToInt32(s);
        }
        if (radioUSD.Checked)
            p.CurrencySalary = radioUSD.Text;
        if (radioVND.Checked)
            p.CurrencySalary = radioVND.Text;
        if (cbKnownUs.SelectedValue!="-1")
            p.KnownUsFrom = Convert.ToInt16(cbKnownUs.SelectedValue);
        p.CarreerObjectives = txtCarreerObjectives.Text;

       

        
    }
   
    protected void Check_Skills_Qualifications()
    {
        
      
        if (cbSchool1.SelectedValue == "")

            cbSchool1.SelectedIndex = 0;
            

        if (cbSchool2.SelectedValue == "")

            cbSchool2.SelectedIndex = 0;


        if (cbSchool3.SelectedValue == "")

            cbSchool3.SelectedIndex = 0;

         if (cbSchool4.SelectedValue == "")
        
            cbSchool4.SelectedIndex = 0;

        

        if (cbMajor1.SelectedValue == "")
            cbMajor1.SelectedIndex = 0;
        if (cbMajor2.SelectedValue == "")
            cbMajor2.SelectedIndex = 0;
        if (cbMajor3.SelectedValue == "")
            cbMajor3.SelectedIndex = 0;
        if (cbMajor4.SelectedValue == "")
            cbMajor4.SelectedIndex = 0;
     
    }


    /*---------------new save -------------------------*/


    
    protected void new_save()
    {
        Check_Skills_Qualifications();
        Profiles p = new Profiles();
        Guid id = new Guid();
        id = Guid.NewGuid();
        p.ID = id;
        //workingExperience.ID = skills.ID = interview.ID = r.ID = 
        p.Insert_All_Profile_ID(txtFullName.Text.Trim(),DateTime.Now);
        
        Set_Basic_Info(p);
        p.ID = id;
        p.Update_Basic_Info();
        Set_Personal_Info(p);
        p.Update_Profile();

        Set_Skills_And_Qualifications();
        skills.ID = id;
        skills.Update_Skills_Qualifications();

        Set_Working_Experience();
        workingExperience.ID = id;
        workingExperience.Update_Working_Experience();

        Set_Interview_Evaluation();
        interview.ID = id;
        interview.Update_InterView_Evaluation();

        Set_Recruitment_Info();
        r.ID = id;
        r.Update_Recruitment_Information();
        
    }
    
    //save profile
    protected void btnView_Click(object sender, EventArgs e)
    {
        Profiles p = new Profiles();
        if (txtFullName.Text == "")
            msgBox.ShowMessage("Please enter fullname!");

        else
        {
            new_save();
            msgBox.ShowMessage("Save successful!");
            
            ResetControl(this.Page);
        }

        
 
      
    }
    public static void ResetControl_archive(Page mypage)
    {
        Control myForm = mypage.FindControl("Form1");
        foreach (Control ctrl in myForm.Controls)
        {
            //Clears TextBox
            if (ctrl is System.Web.UI.WebControls.TextBox)
            {
                (ctrl as TextBox).Text = string.Empty;
            }

            //Clears DropDown Selection
            if (ctrl is System.Web.UI.WebControls.DropDownList)
            {
                (ctrl as DropDownList).ClearSelection();
            }

            //Clears ListBox Selection
            if (ctrl is System.Web.UI.WebControls.ListBox)
            {
                (ctrl as ListBox).ClearSelection();
            }

            //Clears CheckBox Selection
            if (ctrl is System.Web.UI.WebControls.CheckBox)
            {
                (ctrl as CheckBox).Checked = false;
            }

            //Clears RadioButton Selection

            if (ctrl is System.Web.UI.WebControls.RadioButtonList)
            {
                (ctrl as RadioButtonList).ClearSelection();
            }

            //Clears CheckBox Selection
            if (ctrl is System.Web.UI.WebControls.CheckBoxList)
            {
                (ctrl as CheckBoxList).ClearSelection();
            }
        }

    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("index.aspx");
    }
    protected Bitmap CropImage(Bitmap bmpSource, Point topleft, Point bottomright)
    { 


        Bitmap bmpCroped = new Bitmap(bottomright.Y - topleft.Y, bottomright.X - topleft.X);
        Graphics g = Graphics.FromImage(bmpCroped);

        g.DrawImage(bmpSource, new Rectangle(0, 0, bmpCroped.Width, bmpCroped.Height)
                    , topleft.X, topleft.Y, bmpCroped.Width, bmpCroped.Height, GraphicsUnit.Pixel);

        g.Dispose();

        return bmpCroped;
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string strFileName = fileUpload.FileName;
        
        if (fileUpload.HasFile)
        {

          
            Bitmap originalBMP = new Bitmap(fileUpload.FileContent);
            int origWidth = originalBMP.Width;
            int origHeight = originalBMP.Height;
            int sngRatio = origWidth / origHeight;
            int thumbnailSize = 250;
            int newWidth, newHeight;

            if (originalBMP.Width > originalBMP.Height)
            {
                newWidth = thumbnailSize;
                newHeight = originalBMP.Height * thumbnailSize / originalBMP.Width;
            }
            else
            {
                newWidth = originalBMP.Width * thumbnailSize / originalBMP.Height;
                newHeight = thumbnailSize;
            }
        
            using (Bitmap bmp = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.DrawImage(originalBMP, 0, 0,newWidth,newHeight);

                    Bitmap bmpCroped = new Bitmap(bmp);

                    bmpCroped=CropImage(bmp, new Point(0, 0), new Point(120, 140));                   
                    bmpCroped.Save(Server.MapPath("~/images_profiles/" + fileUpload.FileName), ImageFormat.Jpeg);
                }
            }
          GC.Collect(); 
        }
        imgProfile.ImageUrl = "~/images_profiles/" + fileUpload.FileName;
        strImageProfile = "~/images_profiles/" + fileUpload.FileName;
        
    }
    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
       //
        Session.Clear();
        Response.Redirect("../login/login.aspx");

    }


    private void EmptyTextbox()
    {
        txtSchoolID.Text = "";
        txtSchoolName.Text = "";
        txtTenNganhHoc.Text = "";
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string sql=string.Empty;
     
        if (txtSchoolID.Text != ""&&txtSchoolName.Text!="")
        {

            s.SchoolID = txtSchoolID.Text.Trim();
            s.SchoolName = txtSchoolName.Text.Trim();

            if (!s.School_Exists())
            {

                //s.Insert_School();
                sql = "insert into tbl_schools(school_id,schoolname) values('" + txtSchoolID.Text.Trim() + "',N'" + txtSchoolName.Text.Trim() + "')";
                SqlHelper.ExecuteNonQuery(Common.strConnect, CommandType.Text, sql);


                EmptyTextbox();
                
                s.Init_Schools2(cbSchool1, cbSchool2, cbSchool3, cbSchool4);
                dlgAddSchool.ShowOnPageLoad = false;

            }
            else
                msgBox.ShowMessage("Mã trường học đã có.");
            
            
        }
         //strMessage = "Tên trường học đã có";
    }


    protected void imgAddSchool1_Click(object sender, ImageClickEventArgs e)
    {
        
        //popupEdit.Show();
        txtSchoolID.Text = "";
        txtSchoolName.Text = "";
        dlgAddSchool.ShowOnPageLoad = true;

    }
    protected void imgAddMajor1_Click(object sender, ImageClickEventArgs e)
    {

        //popupNganhHoc.Show();
        txtTenNganhHoc.Text = "";
        dlgNganhHoc.ShowOnPageLoad = true;
    }
    protected void btnAddNganhHoc_Click(object sender, EventArgs e)
    {
        string sql = string.Empty;

        if (txtTenNganhHoc.Text != "")
        {
            m.MajorSubjectName = txtTenNganhHoc.Text.Trim();
            if (!m.Major_Exist())
            {
                sql = "insert into tbl_majorsubject2(majorsubject_name,active) values(N'" + txtTenNganhHoc.Text.Trim() + "','1')";
                SqlHelper.ExecuteNonQuery(Common.strConnect, CommandType.Text, sql);
                EmptyTextbox();
                m.Init_Major_Subject3(cbMajor1, cbMajor2, cbMajor3, cbMajor4);
                dlgNganhHoc.ShowOnPageLoad = false;
            }
            else
            { 
                /*
                popupNganhHoc.Show();
                strMessage = "Tên ngành học đã có.";*/
                msgBox.ShowMessage("Tên ngành học đã có.");
                
            }
        }

    }

    protected void btnCancelAddNganhHoc_Click(object sender, EventArgs e)
    {
        dlgNganhHoc.ShowOnPageLoad = false;
    }
    protected void btnCancelAddSchool_Click(object sender, EventArgs e)
    {
        dlgAddSchool.ShowOnPageLoad = false;
    }
}
